package com.atu.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static javax.swing.text.html.CSS.getAttribute;


public class ServletContext_Map_2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context = getServletContext();
        System.out.println(context.getAttribute("key1"));
        System.out.println(context.getAttribute("key2"));
        /**
         *  A.setAttribute(String,String):
         *  由实例对象A设置键值对的值，就应该由A去除键值对的值。这样可以实现值在不同程序中的传递；否则获取不到原本设置的值
         */
        System.out.println(request.getAttribute("key1"));
        System.out.println(request.getAttribute("key2"));
        System.out.println("-------------------------------");
        //只能利用键值对前一个key的值获取后面的值，不能反过来获取值
        System.out.println(context.getAttribute("value1"));
        System.out.println(context.getAttribute("value2"));

    }
}
